package control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.UserDB;

@WebServlet("/ReturnIsValidUser")

/**
 * 验证提交的user、password是否存在于数据库
 * @author faith
 *
 */
public class ReturnIsValidUser extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setHeader("Access-Control-Allow-Origin", "*");
		
		String user = req.getParameter("user");
		String password = req.getParameter("password");
		
		System.out.println(user+password);
		
		UserDB ctrl = new UserDB();
		boolean returnValid = ctrl.isValidUser(user, password);

	    resp.setCharacterEncoding("utf-8");
	    resp.setContentType("text/plain;charset=utf-8");
		PrintWriter out = resp.getWriter();
		out.print(returnValid);
		out.close();
	}
}
